/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.beautycenter.ModelosTabela;

import com.toedter.calendar.JDateChooser;
import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author magelinha
 */
public class JTableDateChooserEditor extends AbstractCellEditor implements TableCellEditor {

    private JDateChooser campo = new JDateChooser();
        
    @Override
    public Object getCellEditorValue() {
        if(campo.getDate() == null) return null;
        
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");  
        return formato.format(campo.getDate());
    }

    @Override
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        Date data = null;
        
        if(value instanceof Date){
            data = (Date)value;
        }
        
        campo.setDate(data);
        
        return campo;
    }
    
}
